package com.gewu.teday.activity

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.util.Log
import android.view.Gravity
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.gewu.teday.R
import com.gewu.teday.utils.GwDialog
import com.gewu.teday.utils.TestRandom
import com.gewu.teday.utils.Util


abstract class BaseActivity : AppCompatActivity() {

    private var gwDialog: GwDialog? = null
    private var layoutBuilder: GwDialog.LayoutBuilder? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayout())

        gwDialog = GwDialog(this)
        layoutBuilder = gwDialog?.LayoutBuilder()

        Util.setStatusOrNavigationColor(this, R.color.beijing)
        initView()
        initData()
    }

    private fun tast() {
        handler.post(runnable)
    }

    private val runnable: Runnable = object : Runnable {
        override fun run() {
            handler.sendEmptyMessage(0)
            handler.postDelayed(this, 1500)
        }
    }

    val handler: Handler = object : Handler(Looper.getMainLooper()) {
        override fun handleMessage(msg: Message) {
            Toast.makeText(application,"联系开发者试用试用试用试用试用试用试用试用试用试用试用试用试用试用",Toast.LENGTH_LONG).show()
        }
    }

    private fun showWindow() {
        val create = layoutBuilder!!.create(R.layout.activity_other,
            false,
            Gravity.CENTER,
            R.drawable.shape_tixian, this.let { it1 -> gwDialog!!.getScreenW(it1) } / 10 * 8)

        Handler().postDelayed(
            {
                create.show()
            },
            1000*60*10
        )
    }

    abstract fun getLayout(): Int
    abstract fun initView();
    abstract fun initData()

}

